package com.ydc.ln.tutorial.j2se.test;
public class JavaTest_demo {
	public static void main(String[] args) {
		System.out.println(reverse("abcd"));
	}

	public static String reverse(String str) {
		char[] strArray = str.toCharArray();
		char temp;
		for (int i=0; i<strArray.length/2; i++) {
			temp = strArray[i];
			strArray[i] = strArray[strArray.length - 1 - i];
			strArray[strArray.length - 1 - i] = temp;
		}
		return new String(strArray);
	}
	
	public static int binarySearch(int[] list, int key, int low, int high) {
		if(low > high) {
			return -1;
		}
		int mid = (low + high) / 2;
		if (key < list[mid]) {
			return binarySearch(list, key, low, mid - 1);
		} else if (key == list[mid]){
			return mid;
		} else {
			return binarySearch(list, key, mid + 1, high);
		}
	}
	
	public static void sort(double[] list, int high) {
		if (high > 1) {
			int indexOfMax = 0;
			double max = 0;
			for (int i = 0; i <= high; i++) {
				if (list[i] > max) {
					indexOfMax = i;
					max = list[i];
				}
			}
			list[indexOfMax] = list[high];
			list[high] = max;
			sort(list, high - 1);
		}
	}

	public static boolean palindrome2(String str, int low, int high) {
		if (low >= high) {
			return true;
		} else if (str.charAt(low) != str.charAt(high)) {
			return false;
		} else {
			return palindrome2(str, low + 1, high - 1);
		}
	}

	public static boolean palindrome(String str) {
		boolean flag = true;
		for (int i = 0; i < str.length() / 2; i++) {
			if (str.charAt(i) != str.charAt(str.length() - i - 1)) {
				flag = false;
				break;
			}
		}
		return flag;
	}

	public static int feibo(int n) {
		if (n == 1 || n == 2) {
			return 1;
		} else {
			return feibo(n - 1) + feibo(n - 2);
		}
	}

	public static int jiecheng(int n) {
		if (n == 1) {
			return 1;
		} else {
			return n * jiecheng(n - 1);
		}
	}
}
